package com.example.demo.interceptor;

import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

@Service
public class QpsScheduler {


    private final QpsInterceptor qpsInterceptor;

    public QpsScheduler(QpsInterceptor qpsInterceptor) {
        this.qpsInterceptor = qpsInterceptor;
    }

    @Scheduled(fixedRate = 1000)
    public void calculateQps() {
        qpsInterceptor.calculateQps();
        //格式化成1位小数
        System.out.printf("current QPS: %.1f\n", qpsInterceptor.getQps());
    }
}  